import { RecommendList } from '@/services';
import { recommendObject } from '@/types';
import { Effect, ImmerReducer, Reducer, Subscription } from 'umi';

export interface RecommendModelState {
    RecommendList: recommendObject[]
}

export interface RecommendModelType {
    namespace: 'recommend';
    state: RecommendModelState;
    effects: {
        getRecommend: Effect;
    };
    reducers: {
        save: Reducer<RecommendModelState>;
    };
}

const RecommendModel: RecommendModelType = {
    namespace: 'recommend',

    state: {
        //文章推荐阅读
        RecommendList: []
    },

    effects: {
        // 归档推荐阅读
        *getRecommend({ payload }, { call, put }) {
            const result = yield call(RecommendList)
            console.log(result.data, "result.dataresult.dataresult.dataresult.dataresult.datav");
            if (result.data) {
                yield put({
                    type: "save",
                    payload: {
                        RecommendList: result.data
                    }
                })
            }
        }

    },
    reducers: {
        save(state, action) {
            return {
                ...state,
                ...action.payload,
            };
        },
    },
};

export default RecommendModel;